﻿Module GenericDao

    Public Function searchData(ByVal stringTable As String, ByVal stringSelect As String) As Data.DataTable
        DataAccessConnection.openConnection()

        Dim command As New Data.OleDb.OleDbCommand
        Dim table As New Data.DataTable

        command.CommandType = CommandType.Text
        command.CommandText = "SELECT " & stringSelect & " FROM " & stringTable

        command.Connection = connection

        table.Load(command.ExecuteReader)

        DataAccessConnection.closeConnection()

        Return table
    End Function

    Public Function searchDataById(ByVal stringTable As String, ByVal stringSelect As String, ByVal id As Integer) As Data.DataTable
        DataAccessConnection.openConnection()

        Dim command As New Data.OleDb.OleDbCommand
        Dim table As New Data.DataTable

        command.Connection = connection
        command.CommandType = CommandType.Text
        command.CommandText = "SELECT " & stringSelect & " FROM " & stringTable & " WHERE id = " & id

        table.Load(command.ExecuteReader)
        DataAccessConnection.closeConnection()

        Return table
    End Function

    Public Sub deleteById(ByVal stringTable As String, ByVal id As Integer)
        DataAccessConnection.openConnection()
        Dim command As New Data.OleDb.OleDbCommand
        Dim table As New Data.DataTable

        command.Connection = connection
        command.CommandType = CommandType.Text
        command.CommandText = "DELETE FROM " & stringTable & " WHERE id = " & id

        table.Load(command.ExecuteReader)
        DataAccessConnection.closeConnection()

    End Sub
End Module
